package com.aken.imdemo.net

import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory

class NetWorkManager {
    /**
     * 初始化必要对象和参数
     */
    fun init() {
        // 初始化Retrofit
        retrofit = Retrofit.Builder()
            .baseUrl(ApiService.HOST)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }

    companion object {
        private var mInstance: NetWorkManager? = null
        private var retrofit: Retrofit? = null

        @Volatile
        var apiService: ApiService? = null
            get() {
                if (field == null) {
                    synchronized(ApiService::class.java) {
                        field =
                            retrofit!!.create(
                                ApiService::class.java
                            )
                    }
                }
                return field
            }
            private set
        val instance: NetWorkManager?
            get() {
                if (mInstance == null) {
                    synchronized(NetWorkManager::class.java) {
                        if (mInstance == null) {
                            mInstance = NetWorkManager()
                        }
                    }
                }
                return mInstance
            }

        //    public static int TESTAPPID = 1400383481;
        var TESTAPPID = 1400038996
        var TESTLIVEID = "@TGS#aFQGYTAFD"

        //    public static String TESTLIVEID = "@TGS#aVH2BXQGS";
        var TESTRSIG =
            "631cdf27de1c1b7410fce46145b8369e84c06a5262cb9fa5bd7bf076a2da1542"
        var USERSIG: String? = null
        var SDKAPPID = 0
        var TOKEN: String? = null
        var LIVEID = 1

    }
}